﻿<!doctype html>
<html>

<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <script type="text/javascript" src="../js/libs/flexible.js"></script>
    <link href="../css/mui.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="../css/base.css" />
    <link rel="stylesheet" href="../css/app/home.css" />
</head>

<body>
    <div id="app" class="mui-content">
        <div class="user-header">
            <div class="index_Title" v-text="title"></div>
            <div id="waitTask" class="waitTask"><span v-text="result.totalTaskNum"></span>个</div>
            <div class="divInfo">待处理任务，请及时处理</div>
            <div class="divBtn">
                <button type="button" class="mui-btn mui-btn-primary" v-on:tap="toWaitDoTaskNow()">立即处理</button>
            </div>
            <div id="user-header-bottom" class="user-header-bottom">
                <a v-for="(item,index) in result.list" class="vertical-bar" v-on:tap="toWaitDoTask(item,index)" v-bind:id="item.id" v-bind:style="{width:100/result.list.length+'%'}">
                    <span class="font-Tag" v-text="item.taskNum"></span>
                    <p v-text="item.title"></p>
                </a>
            </div>
        </div>
        <ul class="mui-table-view">
            <li class="mui-table-view-cell" style="line-height: 0.98rem;font-size: 12px;">
                <p>工作台管理</p>
            </li>
        </ul>
        <div v-if="menus.length>0" v-cloak>
            <ul class="mui-table-view mui-grid-view mui-grid-9" style="border-top: 0px;">
                <li v-for="(item,index) in menus" v-on:tap="goTaskType(item.name,item.title,item.url)" class="mui-table-view-cell mui-media mui-col-xs-6 mui-col-sm-6">
                    <a href="#">
                        <span class="mui-icon" v-bind:class="item.icon" v-bind:style="{background:item.bgColor}">
                            <!--<span  class="mui-badge" v-text="item.taskNum"></span>-->
                        </span>
                        <div class="mui-media-body" v-text="item.title"></div>
                    </a>
                </li>
            </ul>
        </div>
    </div>
    <div id="repair-ways" class="mui-popover mui-popover-bottom mui-popover-action">
        <!-- 可选择菜单 -->
        <ul class="mui-table-view mui-grid-view mui-grid-9">
            <li class="mui-table-view-cell mui-media mui-col-xs-12">
                <span>报修方式</span>
            </li>
            <li class="mui-table-view-cell mui-media mui-col-xs-6 mui-col-sm-6 bor-noright">
                <a href="#" id="btnTextRepair">
                    <span class="mui-icon iconfont icon-bianji"></span>
                    <div class="mui-media-body">文字</div>
                </a>
            </li>
            <li class="mui-table-view-cell mui-media mui-col-xs-6 mui-col-sm-6">
                <a href="#" id="btnSama">
                    <span class="mui-icon iconfont icon-saoma"></span>
                    <div class="mui-media-body">扫一扫</div>
                </a>
            </li>
            <li class="mui-table-view-cell mui-media mui-col-xs-12 p-notop">
                <a href="#repair-ways" class="p-notop"><span class="mui-icon mui-icon-closeempty"></span></a>
            </li>
        </ul>
    </div>
    <script src="../js/mui.min.js"></script>
    <script src="../js/libs/vue.min.js"></script>
    <!--<script src="../js/libs/h.min.js"></script>-->
    <script type="text/javascript" src="../js/common/config.js"></script>
    <script src="../js/common/webSql.js"></script>
    <script src="../js/libs/mock-min.js"></script>
    <script type="text/javascript" src="../js/common/global.js"></script>
    <script src="../js/common/mockdata.js"></script>
    <script type="text/javascript">
        var webview_WaitDoTask = null; //详情页webview
        var app = new Vue({
            el: '#app',
            data: {
                title: '',
                result: {
                    totalTaskNum: 0,
                    list: []
                },
                typeSums: 0,
                menus: []
            },
            methods: {
                toWaitDoTask: function (item, index) {
                    var typeid = item.name;
                    var taskNum = item.taskNum;
                    console.log('item:' + JSON.stringify(item))
                    g.openWindow({
                        url: 'home/waitdo-task-main.html',
                        id: 'waitdo-task-main',
                        extras: {
                            typeid: typeid,
                            index: index,
                            headData: this.result.list
                        }
                    })
                },
                //立即处理
                toWaitDoTaskNow: function () {
                    app.toWaitDoTask(app.result.list[0], 0);
                },
                goTaskType: function (typeid, title, url) {
                    console.log(typeid + ',' + url + ',' + title)
                    var msg = url == "home/total-view.html" ? title + "工单" : title;
                    g.openWindow({
                        url: url,
                        id: url,
                        extras: {
                            typeid: typeid,
                            title: title
                        }
                    });
                },
                //加载任务数
                loadTaskNum: function () {
                    app.result.list = g.getCount(app.result.list, app.getNumber);
                },
                getNumber: function (number) {
                    if (number) {
                        app.result.totalTaskNum = number;
                    }
                }
            },
            mounted: function () {
                var _self = this;
                _self.title = config.appTitle;
                mui.init();
                mui.ready(function () {
                    eventListener();/*高度定位START*/
                    var clientWidth = document.body.clientWidth;
                    var marginTop = '1rem';
                    if (clientWidth <= 320) {
                        marginTop = '0.7rem';
                        document.getElementById("waitTask").style.marginTop = marginTop;
                        document.getElementById("user-header-bottom").style.marginTop = '0.8rem';
                    }
                    /*高度定位END*/
                });
                mui.plusReady(function () {
                    _self.menus = smp_menu.getTwoLevelMenus(1);//1表示班组和项目经理工作台菜单的主键ID
                    //console.log('menus:'+JSON.stringify(_self.menus))
                    var _length = _self.menus.length;
                    if (_length > 0) {
                        for (var i = 0; i < _length; i++) {
                            if (i == 3) {
                                break;
                            }
                            var _temp = {
                                id: '',
                                name: '',
                                title: '',
                                taskNum: 0
                            };
                            _temp.id = _self.menus[i].id;
                            _temp.name = _self.menus[i].name;
                            _temp.title = _self.menus[i].title;
                            _self.result.list.push(_temp);
                        }
                    }
                    var vw = plus.webview.currentWebview();
                    vw.addEventListener("show", _self.loadTaskNum(), false);
                });
            }
        });
        function eventListener() {
            //文字报修
            document.getElementById('btnTextRepair').addEventListener('tap', function () {
                mui('#repair-ways').popover('hide');
                g.openWindowWithTitle({
                    url: 'home/add-repair-content.html',
                    id: "add-repair-content"
                }, '填写报修内容');
            })
            //扫码
            document.getElementById('btnSama').addEventListener('tap', function () {
                mui('#repair-ways').popover('hide');
                g.openWindowWithTitle({
                    url: 'home/barcode-scan.html',
                    id: "barcode-scan"
                }, '二维码扫描');
            })
        }
        //二维码扫描后的回调（类型、结果、文件）
        function scaned(t, r, f) {
            console.log('r:' + r);
            var buildId = g.getBuildId(r);
            g.scanedRepair(buildId);
        }
        function getListAll() { } //空方法
        //显示报修界面
        function showRepair() {
            mui('#repair-ways').popover('show');
        }
    </script>

</body>

</html>